package com.etv.launcher.ui.component.status;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.constraintlayout.widget.Constraints;

import com.etv.launcher.R;

public class UIBluetoothStatusView extends BaseStatusComponent {
    private ImageView iconView;

    public UIBluetoothStatusView(Context context) {
        super(context);
        init();
    }

    public UIBluetoothStatusView(Context context, int widthDp, int heightDp) {
        super(context, widthDp, heightDp);
        init();
    }

    public UIBluetoothStatusView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public UIBluetoothStatusView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        this.setLayoutParams(new Constraints.LayoutParams(80,80));
        iconView = new ImageView(getContext());
        iconView.setId(View.generateViewId());
        LayoutParams iconParams = new LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT
        );
        iconParams.setMargins(10,10,10,10);
        iconView.setLayoutParams(iconParams);
        iconView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        iconView.setImageResource(R.drawable.bluetooth_icon);

        // 添加iconView到布局中
        addView(iconView);

        // 设置约束
        ConstraintSet set = new ConstraintSet();
        set.clone(this);
        set.connect(iconView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
        set.connect(iconView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
        set.connect(iconView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
        set.connect(iconView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
        set.applyTo(this);
    }
}